package cn.dnui_wwt524.dnuifood_16110100524.controller;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Window;
import android.widget.Toast;

import java.util.List;

import cn.dnui_wwt524.dnuifood_16110100524.Adapter.SearchInfoAdapter;
import cn.dnui_wwt524.dnuifood_16110100524.R;
import cn.dnui_wwt524.dnuifood_16110100524.bean.FoodBean;
import cn.dnui_wwt524.dnuifood_16110100524.bean.SearchBean;
import cn.dnui_wwt524.dnuifood_16110100524.listener.OnRetrofitListener;
import cn.dnui_wwt524.dnuifood_16110100524.model.SearchModel;

public class SearchInfoActivity extends AppCompatActivity implements OnRetrofitListener<List<SearchBean>> {
    private SearchInfoAdapter searchInfoAdapter;
    private RecyclerView recyclerView;
    String search;

    void initViews() {
        recyclerView = (RecyclerView)findViewById(R.id.search_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }


    void initDate() {
        SearchModel searchModel = new SearchModel();
        searchModel.getSearchByFood(search,this);//访问服务器请求
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_search_info);

        search = getIntent().getStringExtra("search");

        initViews();
        initDate();

    }

    @Override
    public void onSuccess(List<SearchBean> object, int flag) {
        searchInfoAdapter = new SearchInfoAdapter(SearchInfoActivity.this, object, R.layout.activity_search_info);
        recyclerView.setAdapter(searchInfoAdapter);
    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(this, "网络连接失败", Toast.LENGTH_SHORT).show();

    }
}
